﻿using Code;
using HeerCards;
using LitJson;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace github.heerheer.card2.UI.ViewModels
{
    [AddINotifyPropertyChangedInterface]
    public class PoolEditorViewModel
    {
        public ObservableCollection<HCPool> Pools { get; set; } = new ObservableCollection<HCPool>();

        public PoolEditorViewModel()
        {
            Pools = new ObservableCollection<HCPool>(getPools());
        }
        public List<HCPool> getPools()
        {
            var p = new List<HCPool>();
            if (!Directory.Exists(AppMain.Common?.AppDirectory + "pools"))
            {
                Directory.CreateDirectory(AppMain.Common?.AppDirectory + "pools");
            }
            foreach (var item in Directory.GetFiles(AppMain.Common?.AppDirectory + "pools", "*.json"))
            {
                p.Add(JsonMapper.ToObject<HCPool>(new JsonReader(File.ReadAllText(item))));
            }
            return p;
        }
    }
}
